#ifndef NTP_H
#define NTP_H
#include<stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include<unistd.h>
#include<time.h>
#include<string.h>
#include <stdlib.h>

//1900.1.1-1970.1.1之间的相差的秒值
#define NTP_TIME_1900_1970  2208988800
#define NTP_PORT_SERVER 123 
#define NTP_VERSION 3
#define NTP_MODE    3
//
#define NTP_RESEND_TIME_S 2
#define NTP_RESEND_MAX_NUM 3

//单字节对齐
#pragma pack(1)

typedef struct _ntp_time_t {
    uint32_t seconds;
    uint32_t fraction;
}ntp_time_t;

typedef struct _ntp_pkt_t {
    uint8_t LI_VN_Mode;
    uint8_t stratum;
    uint8_t poll;
    uint8_t precision;
    uint32_t root_delay;
    uint32_t root_dispersion;
    uint32_t ref_id;
    ntp_time_t ref_ts;
    ntp_time_t orig_ts;
    ntp_time_t recv_ts;
    ntp_time_t trans_ts;
}ntp_pkt_t;

#pragma pack()

struct tm* ntp_get_time(const char* server);
void creat_udp_sockaddr(struct sockaddr_in * addr, const char* ipStr);



#endif